<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use App\Post;

class BlogController extends Controller
{
    /**
     * blog post list
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $posts = Post::where('published_at', '<=', Carbon::now())->orderBy('published_at', 'DESC')->paginate(config('blog.posts_per_page'));

        return view('blog.index', compact('posts'));
    }

    /**
     * blog post
     *
     * @param $slug
     * @return mixed
     */
    public function showPost($slug)
    {
        $posts = Post::whereSlug($slug)->firstOrFail();

        return view('blog.post')->withPost($posts);
    }
}
